<template>
	<div class="risk">
		<van-search
			class="info_search"
			v-model="value"
			@search="onSearch"
			@clear="clearSearch"
			show-action
			placeholder="搜索"
		>
			<template #action>
				<div @click="submit">完成</div>
			</template>
		</van-search>
		<van-list
			style="margin-top: 10px"
			:finished="finished"
			v-model="loading"
			finished-text="没有更多了"
		>
			<van-checkbox-group @change="handleChange" v-model="result">
				<van-cell v-for="(item, index) in list" :key="index" :border="false">
					<div class="risk_item_radio">
						<div>
							<div class="mb-10">{{ item.OrgName }}</div>
							<div>{{ item.OrgFullName }}</div>
						</div>
						<van-checkbox :name="item.OrgCode"></van-checkbox>
					</div>
				</van-cell>
			</van-checkbox-group>
		</van-list>

		<!-- <div class="risk_item_radio">
            <div>
                <div class="mb-10">所有部门</div>
                <div>所有部门</div>
            </div>
       <van-checkbox name="{a:ggg,c:xxx}"></van-checkbox>
        </div>
        <div class="risk_item_radio">
            <div>
                <div class="mb-10">所有部门</div>
                <div>所有部门</div>
            </div>
         <van-checkbox name="{a:ggg,c:xxx}"></van-checkbox>
        </div> -->
	</div>
</template>

<script>
import { getRiskDepartList } from '@/api/common'
export default {
	data() {
		return {
			list: [],
			result: [],
			loading: false,
			finished: false,
			filter: {
				page: 0,
				showMyDept: false,
				onlyMyDept: false,
				accounted: true,
				orgType: 'D',
			},
			activeNames: ['1'],
			border: false,
			value: '',
			radio: '',
			newArr: [],
			options: [],
		}
	},
	created() {
		this.getList()
	},
	methods: {
		handleChange(val) {
			let newArr = []
			this.list.forEach((item) => {
				val.forEach((item1) => {
					if (item.OrgCode == item1) {
						newArr.push({
							OrgCode: item.OrgCode,
							OrgName: item.OrgName,
						})
					}
				})
			})
			this.newArr = newArr
		},
		// 完成
		submit() {
			// this.$router.push({
			// 	name: 'edit-chemical',
			// 	params: { OrgCode: this.newArr },
			// })
			this.$emit('cb', this.newArr)
		},
		getList() {
			this.loading = true
			getRiskDepartList(this.filter)
				.then((res) => {
					this.loading = false
					this.list = res.data

					this.options = res.data
					this.finished = true
					//this.filter.page = res.data.PageIndex;
				})
				.catch((err) => {
					this.finished = true
				})
		},

		// 文件页面
		goFile() {
			// this.$router.push('/CommonInfo/InfoDetail')
		},
		onSearch(val) {
			if (val) {
				this.list = this.fuzzyQuery(this.options, val, 'OrgName')
			}
		},
		clearSearch() {
			this.list = this.options
		},
		fuzzyQuery(list, keyWord, type) {
			var arr = []
			list.map((item) => {
				if (item[type].indexOf(keyWord) >= 0) {
					arr.push(item)
				}
			})

			return arr
		},
	},
}
</script>

<style lang="less" scoped>
.risk {
	background-color: #e8f1f8;
	.info_search {
		padding: 10px;
		border-radius: 5px !important;
		.van-field__control {
			background-color: #ffffff !important;
		}
	}
}
.risk_item_radio {
	width: 100%;

	background-color: #fff;
	display: flex;
	justify-content: space-between;
	align-items: center;
	border-bottom: 1px solid #e8f1f8;
}
</style>
